package com.hzncc.scaffold.controller.Rear.teachingClassroom.QA;

import com.hzncc.scaffold.core.ResultT;
import com.hzncc.scaffold.entity.Other.Reply;
import com.hzncc.scaffold.entity.Vo.ReplyIdVo;
import com.hzncc.scaffold.service.ReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: DrunkBear
 * @Date: 2022-05-12 22:48
 * @Description: null
 */

@Api(tags = "教学课堂管理-问答管理-回答管理")
@RequestMapping("/manage/reply")
@RestController
public class ReplyManagementController {

    @Autowired
    ReplyService replyService;

    @GetMapping("/list")
    @ApiOperation("获取回答管理列表")
    public ResultT list(Integer pageNum, Integer pageSize, String keyword, Integer courseId, Integer status) {
        ResultT resultT = replyService.list(pageNum, pageSize, keyword, courseId, status);
        return resultT;
    }

    @PostMapping("/delete")
    @ApiOperation("根据编号删除问题")
    public ResultT delete(@RequestBody ReplyIdVo replyIdVo) {

        Integer replyId = replyIdVo.getReplyId();

        boolean remove = replyService.removeById(replyId);
        if (remove) {
            return ResultT.success("删除成功");
        } else {
            return ResultT.fail("删除失败");
        }
    }


    @PostMapping("/refuse")
    @ApiOperation("根据编号不通过回答")
    public ResultT refuse(@RequestBody ReplyIdVo replyIdVo) {

        Integer replyId = replyIdVo.getReplyId();

        if (replyService.getById(replyId) != null) {
            Reply reply = replyService.getById(replyId);
            reply.setStatus(2);
            boolean update = replyService.updateById(reply);
            if (update) {
                return ResultT.success("操作成功");
            } else {
                return ResultT.fail("操作失败");
            }
        } else {
            return ResultT.fail("数据错误");
        }
    }

    @PostMapping("/publish")
    @ApiOperation("根据编号通过回答")
    public ResultT publish(@RequestBody ReplyIdVo replyIdVo) {

        Integer replyId = replyIdVo.getReplyId();

        if (replyService.getById(replyId) != null) {
            Reply reply = replyService.getById(replyId);
            reply.setStatus(1);
            boolean update = replyService.updateById(reply);
            if (update) {
                return ResultT.success("操作成功");
            } else {
                return ResultT.fail("操作失败");
            }
        } else {
            return ResultT.fail("数据错误");
        }
    }
}
